RichTextBox for UWP | ComponentOne
Working with RichTextBox for UWP / Setting and Formatting Content / Setting Rtf Content
In This Topic
    Setting Rtf Content
    In This Topic

    You can read, edit, and display rich text formatted documents using the C1RichTextBox control. To set RTF content in the C1RichTextBox control, you must use a separate RtfFilter class. This class allows you to convert RTF to a Document that the control can understand.

    The RtfFilter includes support for images, fonts, tables, and most formatting supported by Microsoft WordPad. You can also use the control to convert RTF to HTML and vice versa, since the C1RichTextBox control also supports reading and writing HTML.

     

    To load an RTF string into a C1RichTextBox control,  call the ConvertToDocument method from the RtfFilter class:

    C#
    Copy Code
    string rtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
    {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\f0\fs22 some rtf content\par
    }";
    C1RichTextBox1.Document = new RtfFilter().ConvertToDocument(rtf);
    

    To output the content of C1RichTextBox as RTF, call the ConvertFromDocument method.

    C#
    Copy Code
    string rtf = new RtfFilter().ConvertFromDocument(c1RichTextBox1.Document);